<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript">
function getNode(){
	var h1Node = document.getElementById("title");
	alert(h1Node);
	//alert(h1Node.firstChild.nodeValue);
	//alert(h1Node.lastChild.nodeValue);
	alert(h1Node.childNodes[0].nodeValue);
	//通过标签名称获取节点对象，返回结果是一个数组
	var nodes = document.getElementsByTagName("h1");
	for(var i=0;i<nodes.length;i++){
		var node = nodes[i];
		alert(node.childNodes[0].nodeValue+"<br/>");
	}
	
	var msgNodes = document.getElementsByName("msg");
	for(var i=0;i<msgNodes.length;i++){
		var node = msgNodes[i];
		alert(node.childNodes[0].nodeValue+"<br/>");
	}
}
</script>
</head>

<body onload="getNode()">
<h1 id="title">获取标题</h1>
<p>hello world</p>
<p name="msg">hello yitong</p>
<p name="msg">hello stx</p>
</body>
</html>
